import httpRequest from "@/utils/http-request.js";

/**
 * 加载所有
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const all = () => {
    return httpRequest.get("/sys/role/all");
}

/**
 * 分页查询
 * @param page
 * @param size
 * @returns {*}
 */
export const page = (page, size) => {
    return httpRequest.get(`/sys/role/page/${page}/${size}`);
}

/**
 * 新增
 * @param name
 * @param dataScope
 * @param permission
 * @param sort
 * @param deptIds
 * @param menuIds
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const add = ( {name, dataScope, permission, sort, deptIds, menuIds}) => {
    return httpRequest.post("/sys/role", {
        name,
        dataScope,
        permission,
        sort,
        deptIds,
        menuIds
    });
}

/**
 * 根据ID修改
 * @param id
 * @param name
 * @param dataScope
 * @param permission
 * @param sort
 * @param deptIds
 * @param menuIds
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const modifyById = (id, {name, dataScope, permission, sort, deptIds, menuIds}) => {
    return httpRequest.put(`/sys/role/${id}`, {
        name,
        dataScope,
        permission,
        sort,
        deptIds,
        menuIds
    });
}

/**
 * 详情
 * @param id
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const detailById = (id) => {
    return httpRequest.get(`/sys/role/detail/${id}`);
}

/**
 * 根据ID删除
 * @param id
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const deleteById = (id) => {
    return httpRequest.delete(`/sys/role/${id}`);
}
